package com.zhang.table;

import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaProducer;
import org.apache.kafka.clients.consumer.ConsumerConfig;

import java.util.Properties;

/**
 * @title:
 * @author: zhang
 * @date: 2022/2/10 20:27
 */
public class KafkaSink {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        Properties properties = new Properties();
        properties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "hadoop302:9092");

        env
                .socketTextStream("localhost", 9999)
                .addSink(new FlinkKafkaProducer<String>(
                        "test_flink",
                        new SimpleStringSchema(),
                        properties
                ));

        env.execute();
    }
}
